package com.web.dao;

import com.github.pagehelper.Page;
import com.web.controller.web.WebStoreController;
import com.web.entity.StoreApply;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * @author FDjavaone
 */
public interface StoreApplyMapper {


    @Delete({
            "delete from t_store_apply",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into t_store_apply (m_id, type,",
            " merchant_name, level, ",
            " logo, licence_no, ",
            " licence_img,identity_a_img,identity_b_img,store_img, contactor, ",
            " contact_phone, contact_tel, ",
            " province, city, ",
            " region, street, ",
            " address, loc,reason, status,storeType ",
            " create_time, modify_time) ",
            " values (#{mId,jdbcType=BIGINT}, #{type,jdbcType=VARCHAR}, ",
            " #{merchantName,jdbcType=VARCHAR}, #{level,jdbcType=VARCHAR}, ",
            " #{logo,jdbcType=VARCHAR}, #{licenceNo,jdbcType=VARCHAR}, ",
            " #{licenceImg,jdbcType=VARCHAR},#{identityAImg,jdbcType=VARCHAR},#{identityBImg,jdbcType=VARCHAR},#{storeImg,jdbcType=VARCHAR}, #{contactor,jdbcType=VARCHAR}, ",
            " #{contactPhone,jdbcType=VARCHAR}, #{contactTel,jdbcType=VARCHAR}, ",
            " #{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, ",
            " #{region,jdbcType=VARCHAR}, #{street,jdbcType=VARCHAR}, ",
            " #{address,jdbcType=VARCHAR}, #{loc,jdbcType=VARCHAR},#{reason,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},#{storeType,jdbcType=VARCHAR}, ",
            " #{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insert(StoreApply record);

    @InsertProvider(type = StoreApplySqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insertSelective(StoreApply record);


    @Select({
            "select ",
            " id, m_id, type, merchant_name, level, logo, licence_no, licence_img,identity_a_img,identity_b_img,store_img, contactor, ",
            " contact_phone, contact_tel, province, city, region, street, address, loc,reason, status,storeType, ",
            " create_time, modify_time ",
            " from t_store_apply ",
            " where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "m_id", property = "mId", jdbcType = JdbcType.BIGINT),
            @Result(column = "type", property = "type", jdbcType = JdbcType.VARCHAR),
            @Result(column = "merchant_name", property = "merchantName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "level", property = "level", jdbcType = JdbcType.VARCHAR),
            @Result(column = "logo", property = "logo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "licence_no", property = "licenceNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "licence_img", property = "licenceImg", jdbcType = JdbcType.VARCHAR),
            @Result(column = "identity_a_img", property = "identityAImg", jdbcType = JdbcType.VARCHAR),
            @Result(column = "identity_b_img", property = "identityBImg", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_img", property = "storeImg", jdbcType = JdbcType.VARCHAR),
            @Result(column = "contactor", property = "contactor", jdbcType = JdbcType.VARCHAR),
            @Result(column = "contact_phone", property = "contactPhone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "contact_tel", property = "contactTel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "province", property = "province", jdbcType = JdbcType.VARCHAR),
            @Result(column = "city", property = "city", jdbcType = JdbcType.VARCHAR),
            @Result(column = "region", property = "region", jdbcType = JdbcType.VARCHAR),
            @Result(column = "street", property = "street", jdbcType = JdbcType.VARCHAR),
            @Result(column = "address", property = "address", jdbcType = JdbcType.VARCHAR),
            @Result(column = "loc", property = "loc", jdbcType = JdbcType.VARCHAR),
            @Result(column = "reason", property = "reason", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "storeType", property = "storeType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    StoreApply selectByPrimaryKey(Long id);


    @UpdateProvider(type = StoreApplySqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(StoreApply record);

    @Update({
            "update t_store_apply ",
            " set m_id = #{mId,jdbcType=BIGINT},",
            " type = #{type,jdbcType=VARCHAR},",
            " merchant_name = #{merchantName,jdbcType=VARCHAR},",
            " level = #{level,jdbcType=VARCHAR},",
            " logo = #{logo,jdbcType=VARCHAR},",
            " licence_no = #{licenceNo,jdbcType=VARCHAR},",
            " licence_img = #{licenceImg,jdbcType=VARCHAR},",
            " identity_a_img = #{identityAImg,jdbcType=VARCHAR},",
            " identity_b_img = #{identityBImg,jdbcType=VARCHAR},",
            " store_img = #{storeImg,jdbcType=VARCHAR},",
            " contactor = #{contactor,jdbcType=VARCHAR},",
            " contact_phone = #{contactPhone,jdbcType=VARCHAR},",
            " contact_tel = #{contactTel,jdbcType=VARCHAR},",
            " province = #{province,jdbcType=VARCHAR},",
            " city = #{city,jdbcType=VARCHAR},",
            " region = #{region,jdbcType=VARCHAR},",
            " street = #{street,jdbcType=VARCHAR},",
            " address = #{address,jdbcType=VARCHAR},",
            " loc = #{loc,jdbcType=VARCHAR},",
            " reason = #{reason,jdbcType=VARCHAR},",
            " status = #{status,jdbcType=INTEGER},",
            " storeType = #{storeType,jdbcType=VARCHAR},",
            " create_time = #{createTime,jdbcType=TIMESTAMP},",
            " modify_time = #{modifyTime,jdbcType=TIMESTAMP} ",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(StoreApply record);

    @Select({
            "select",
            " id, m_id, type, merchant_name, level, logo, licence_no, licence_img,identity_a_img,identity_b_img,store_img, contactor, ",
            " contact_phone, contact_tel, province, city, region, street, address, loc,reason, status,storeType, ",
            " create_time, modify_time ",
            " from t_store_apply ",
            " where m_id = #{id,jdbcType=BIGINT} order by create_time asc"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "m_id", property = "mId", jdbcType = JdbcType.BIGINT),
            @Result(column = "type", property = "type", jdbcType = JdbcType.VARCHAR),
            @Result(column = "merchant_name", property = "merchantName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "level", property = "level", jdbcType = JdbcType.VARCHAR),
            @Result(column = "logo", property = "logo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "licence_no", property = "licenceNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "licence_img", property = "licenceImg", jdbcType = JdbcType.VARCHAR),
            @Result(column = "identity_a_img", property = "identityAImg", jdbcType = JdbcType.VARCHAR),
            @Result(column = "identity_b_img", property = "identityBImg", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_img", property = "storeImg", jdbcType = JdbcType.VARCHAR),
            @Result(column = "contactor", property = "contactor", jdbcType = JdbcType.VARCHAR),
            @Result(column = "contact_phone", property = "contactPhone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "contact_tel", property = "contactTel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "province", property = "province", jdbcType = JdbcType.VARCHAR),
            @Result(column = "city", property = "city", jdbcType = JdbcType.VARCHAR),
            @Result(column = "region", property = "region", jdbcType = JdbcType.VARCHAR),
            @Result(column = "street", property = "street", jdbcType = JdbcType.VARCHAR),
            @Result(column = "address", property = "address", jdbcType = JdbcType.VARCHAR),
            @Result(column = "loc", property = "loc", jdbcType = JdbcType.VARCHAR),
            @Result(column = "reason", property = "reason", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "storeType", property = "storeType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    List<StoreApply> selectByMid(Long id);

    @SelectProvider(type = StoreApplySqlProvider.class, method = "selectAllStoreApply")
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "m_id", property = "mId", jdbcType = JdbcType.BIGINT),
            @Result(column = "type", property = "type", jdbcType = JdbcType.VARCHAR),
            @Result(column = "merchant_name", property = "merchantName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "level", property = "level", jdbcType = JdbcType.VARCHAR),
            @Result(column = "logo", property = "logo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "licence_no", property = "licenceNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "licence_img", property = "licenceImg", jdbcType = JdbcType.VARCHAR),
            @Result(column = "identity_a_img", property = "identityAImg", jdbcType = JdbcType.VARCHAR),
            @Result(column = "identity_b_img", property = "identityBImg", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_img", property = "storeImg", jdbcType = JdbcType.VARCHAR),
            @Result(column = "contactor", property = "contactor", jdbcType = JdbcType.VARCHAR),
            @Result(column = "contact_phone", property = "contactPhone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "contact_tel", property = "contactTel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "province", property = "province", jdbcType = JdbcType.VARCHAR),
            @Result(column = "city", property = "city", jdbcType = JdbcType.VARCHAR),
            @Result(column = "region", property = "region", jdbcType = JdbcType.VARCHAR),
            @Result(column = "street", property = "street", jdbcType = JdbcType.VARCHAR),
            @Result(column = "address", property = "address", jdbcType = JdbcType.VARCHAR),
            @Result(column = "loc", property = "loc", jdbcType = JdbcType.VARCHAR),
            @Result(column = "reason", property = "reason", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "storeType", property = "storeType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    Page<StoreApply> selectAllStoreApply(WebStoreController.StoreApplyColumns storeApplyColumns);

   @Select({
            "select count(0) from t_store_apply where status=0 "
    })
    int countWaiting();
}